home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et-2_2.lha / et2.2 / src / ObjectTable.h < prev    next >
C/C++ Source or Header  |  1990-11-28  |  2KB  |  61 lines

  1. #ifndef ObjectTable_First
  2. #ifdef __GNUG__
  3. #pragma once
  4. #endif
  5. #define ObjectTable_First
  6.  
  7. #include "Types.h"
  8.  
  9. extern class ObjectTable *gObjectTable; // only instance of object table 
  10.  
  11. //---- Object Table ----------------------------------------------------------
  12. // this class registers all instances of Object or its subclasses
  13. // in a hash table
  14.  
  15. class ObjectTable {
  16.     Object **table;
  17.     int size;           
  18.     int tally;
  19.     int cursor;              // for iterating
  20.     class Class *fromClass;  // looking for instances of class in operator()()
  21.     bool members;            // return only direct members of a clas in "   "
  22.     bool inIterator;        
  23.  
  24.     //---- statistics
  25.     int convoi;
  26.     long cumconvoi;
  27.     int seed;
  28.  
  29.     void Expand(int newsize);
  30.     bool HighWaterMark ()
  31.     { return (bool) (tally >= (3 * size /4)); }
  32.     int FindElement (Object*);
  33.     void FixCollisions (int index);
  34. public:
  35.     ObjectTable();
  36.     ~ObjectTable();
  37.     void HashStatistics();
  38.     void AddObject(Object*);
  39.     void RemoveObject(Object*);
  40.     bool PtrIsValidOfObject(Object *);      // check wether the given pointer is valid
  41.     void Start(Class *cl= 0, bool members= TRUE);
  42.     Object *operator()();
  43.     void End();
  44.     void Verify();
  45.     //---- friends
  46.     static void Add(Object *op);
  47.     static void AddRoot(Object *op); // add a root object
  48.     static void AddRoots(Object*, ...);
  49.     static void Remove(Object *op);
  50.     static void UpdateInstCount();
  51.     static bool PtrIsValid(Object *);
  52.     static void VisitObjects();  // visit all objects, reachable 
  53.                         // from root objects
  54.     static int Instances();      // return total number of instances 
  55.     static Object *SomeInstance(Class *);
  56.     static Object *SomeMember(Class *);
  57. };
  58.  
  59. #endif ObjectTable
  60.  
  61.